﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using nvn.Core.MVP;
using Hutech.CRM.Library.Views;
using Hutech.CRM.Library.Models.Entities;
using Hutech.CRM.Library.Utilities;
using nvn.Library.Patterns;
using System.Drawing;

namespace Hutech.CRM.Web.Controls.ManageLevelCustomers
{
    public partial class AddNewCriterionCustomer : System.Web.UI.UserControl, IAddNewCriterionCustomerView
    {
        #region MEMBER VARIABLES
        //protected string EditPropertiesImage = "~/Data/SiteImages/" + WebConfigSettings.EditPropertiesImage;
        //protected string DeleteLinkImage = "~/Data/SiteImages/" + WebConfigSettings.DeleteLinkImage;
        //List<TowTypeParameters<Guid, string>> _GroupLevelCustomers;
        #endregion

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.InitView();

            this.ImageButtonSave.Click += new ImageClickEventHandler(ImageButtonSave_Click);
            this.ImageButtonExit.Click += new ImageClickEventHandler(ImageButtonExit_Click);
        }

        void ImageButtonExit_Click(object sender, ImageClickEventArgs e)
        {
            OnExit_Click();
        }
        void ImageButtonSave_Click(object sender, ImageClickEventArgs e)
        {
            CriterionCustomer item = new CriterionCustomer();
            item.CriterionName = TextBoxCriterionName.Text;
            item.GroupLevelCustomerGuid = new Guid(DropDownListGroupLevelCustomer.SelectedValue.ToString());
            item.GroupLevelCustomerName = DropDownListGroupLevelCustomer.SelectedItem.ToString();
            
            OnSave_Click(item);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                OnFristLoadEventHandler();
        }

        #region Implement from View class
        #region Property
        public string HeaderPopup
        {
            set { LabelHead.Text = value; }
        }
        public string ErrorMessage
        {
            set
            {
                if (value != null)
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Show", "<script type='text/javascript'>alert('" + value + "');</script>", false);
            }
        }
        public string CriterionName
        {
            get
            {
                return TextBoxCriterionName.Text;
            }
            set
            {
                TextBoxCriterionName.Text = value;
            }
        }
        public bool ShowPopup
        {
            set 
            {
                if (value)
                    ModalPopupAddNew.Show();
                else
                    ModalPopupAddNew.Hide();
            }
        }
        public bool UpdatePopup
        {
            set 
            {
                if (value)
                {
                    UpdatePanelAddNew.Update();
                    OnReload_EventAgrs();
                }
            }
        }
        public List<TowTypeParameters<Guid, string>> GroupLevelCustomers
        {
            set
            {
                DropDownListGroupLevelCustomer.Items.Clear();
                DropDownListGroupLevelCustomer.DataSource = value;
                DropDownListGroupLevelCustomer.DataValueField = "T";
                DropDownListGroupLevelCustomer.DataTextField = "V";
                DropDownListGroupLevelCustomer.DataBind();
            }
        }
        #endregion

        #region Event
        public event EventHandler<EventArgs> Reload_EventAgrs;
        private void OnReload_EventAgrs()
        {
            if (Reload_EventAgrs != null)
                Reload_EventAgrs(this, new EventArgs());
        }

        public event EventHandler<EventArgs> Exit_Click;
        private void OnExit_Click()
        {
            if (Exit_Click != null)
                Exit_Click(this, new EventArgs());
        }
      
        public event EventHandler<EventArgs> FristLoadEventHandler;
        private void OnFristLoadEventHandler()
        {
            if (FristLoadEventHandler != null)
                FristLoadEventHandler(this, new EventArgs());
        }

        public event EventHandler<SaveEventAgrs<CriterionCustomer>> Save_Click;
        private void OnSave_Click(CriterionCustomer myType)
        {
            if (Save_Click != null)
                Save_Click(this, new SaveEventAgrs<CriterionCustomer>(myType));
        }
        #endregion
        #endregion
    }
}